Current Location: Home> Function Categories> filter_var_array

filter_var_array

Get multiple variables and filter them
Name:filter_var_array
Category:Filter
Programming Language:php
One-line Description:Get multiple variables and filter them.

Definition and usage

filter_var_array() function obtains multiple variables and filters them.

Since filter_input() is not required to be called repeatedly, this function is useful for filtering multiple variables.

If successful, return an array containing the filtered variable values, and if failed, false.

实例

<?php
$arr = array
 (
 "name" => "peter griffin",
 "age" => "41",
 "email" => "peter@example.com",
 );

$filters = array
 (
 "name" => array
  (
  "filter"=>FILTER_CALLBACK,
  "flags"=>FILTER_FORCE_ARRAY,
  "options"=>"ucwords"
  ),
 "age" => array
  (
  "filter"=>FILTER_VALIDATE_INT,
  "options"=>array
   (
   "min_range"=>1,
   "max_range"=>120
   )
  ),
 "email"=> FILTER_VALIDATE_EMAIL,
 );

print_r(filter_var_array($arr, $filters));
?>

输出类似:

Array
 (
 [name] => Peter Griffin
 [age] => 41
 [email] => peter@example.com
 )

grammar

 filter_var_array ( array , args )
parameter describe
array Required. Specifies an array with string keys that contain the data to be filtered.
args

Optional. Specifies an array of filter parameters.

The legal array key is the variable name. The legal value is the filter ID, or an array of specified filters, flags, and options.

This parameter can also be a separate filter ID, if so, all values ​​in the input array are filtered by the specified filter.

Similar Functions
Popular Articles